package com.powernode.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.powernode.domain.Customer;
import com.powernode.domain.User;
import com.powernode.dto.CustomerDto;
import com.powernode.mapper.CustomerMapper;
import com.powernode.service.CustomerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private CustomerMapper customerMapper;

    @Override
    public PageInfo<User> queryAllCustomer(CustomerDto customerDto) {
        Page<User> page = PageHelper.startPage(customerDto.getPage(), customerDto.getLimit());
        customerMapper.queryAllCustomer(customerDto);
        return page.toPageInfo();
    }

    @Override
    public int insertSelective(Customer record) {
        return customerMapper.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(Customer record) {
        return customerMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public void changeCustomerUser(Integer userId, Integer[] customerIds) {
        if (customerIds != null && customerIds.length > 0 && userId != null) {
            customerMapper.changeCustomerUser(userId, customerIds);
        }
    }
}
